package com.ruoyi.hcrf.controller.agv;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.hcrf.bo.agv.InOutPageInBo;
import com.ruoyi.hcrf.bo.agv.InOutVo;
import com.ruoyi.hcrf.domain.entity.task.InOut;
import com.ruoyi.hcrf.domain.service.agv.InOutService;
import com.ruoyi.hcrf.enums.CommonPage;
import com.ruoyi.hcrf.enums.CommonResultT;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "出入库依赖单据管理")
@RestController
@RequestMapping("/inOut")
public class InOutController {

    @Autowired
    private InOutService inOutService;


    @ApiOperation("分页查询--出库依赖数据")
    @RequestMapping(value = "/findAllByPage", method = RequestMethod.POST)
    @ResponseBody
    public CommonResultT<CommonPage<InOutVo>> findAllByPage(@RequestBody InOutPageInBo pageInBo) {
        Page<InOut> page = inOutService.findAllByPage(pageInBo);
        if (page == null) {
            return CommonResultT.failed("查询失败");
        } else {
            List<InOut> inOuts = page.getRecords();
            Page<InOutVo> pageResult = new Page<>();
            //同属性字段转换
            BeanUtils.copyProperties(page, pageResult);
            List<InOutVo> inOutVos = new ArrayList<>();
            for (InOut inOut : inOuts) {
                InOutVo inOutVo = new InOutVo();
                BeanUtils.copyProperties(inOut, inOutVo);
                inOutVos.add(inOutVo);
            }
            pageResult.setRecords(inOutVos);
            return CommonResultT.success(CommonPage.restPage(pageResult));
        }
    }
    @ApiOperation("分页查询--退库依赖数据")
    @RequestMapping(value = "/ByPage", method = RequestMethod.POST)
    @ResponseBody
    public CommonResultT<CommonPage<InOutVo>> byPage(@RequestBody InOutPageInBo pageInBo) {
        Page<InOut> page = inOutService.ByPage(pageInBo);
        if (page == null) {
            return CommonResultT.failed("查询失败");
        } else {
            List<InOut> inOuts = page.getRecords();
            Page<InOutVo> pageResult = new Page<>();
            //同属性字段转换
            BeanUtils.copyProperties(page, pageResult);
            List<InOutVo> inOutVos = new ArrayList<>();
            for (InOut inOut : inOuts) {
                InOutVo inOutVo = new InOutVo();
                BeanUtils.copyProperties(inOut, inOutVo);
                inOutVos.add(inOutVo);
            }
            pageResult.setRecords(inOutVos);
            return CommonResultT.success(CommonPage.restPage(pageResult));
        }
    }

}
